package com.hsfw.dbmodule.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.lang.management.MemoryUsage;

/**
 * 主要提供系统初始化信息统计与预加载操作
 */
@Component
public class SingleVolDictionary {
    private final Logger log = LoggerFactory.getLogger(SingleVolDictionary.class);


    @PostConstruct
    public void init() {

        MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
        MemoryUsage memoryUsage = memoryMXBean.getHeapMemoryUsage();
        long memoryInitSize = memoryUsage.getUsed();
        log.info("目前使用内存" + memoryInitSize / (1024 * 1024) + "M");
    }


    private volatile static SingleVolDictionary singleVolDictionary;


    private SingleVolDictionary() {
    }

    public static SingleVolDictionary getInstance() {
        if (singleVolDictionary == null) {
            synchronized (SingleVolDictionary.class) {
                if (singleVolDictionary == null) {
                    singleVolDictionary = new SingleVolDictionary();
                }
            }
        }
        return singleVolDictionary;
    }

}
